**************************************** * * * FILE.READ.ASM Source Listing * * by Sandy Mossberg * * * * APW Assembler * * * * Copyright (C) 1989 * * by MindCraft Publ. Corp. * * Concord, MA 01742 * * * **************************************** mcopy file.read.mac keep file.read DPHndl gequ $00 ;handle to direct page space DPPtr gequ $04 ;ptr to direct page space DataBufHndl gequ $08 ;handle to data buffer for file contents DataBufPtr gequ $0C ;ptr to data buffer for file contents PrtRecHndl gequ $10 ;handle to print record PrtRecPtr gequ $14 ;ptr to print record ScreenMode gequ $80 ;640x200 super hi-res ($00 = 320x200) ScreenWidth gequ 640 ;640 pixel screen width top gequ 0 ;offsets in coordinate fields left gequ 2 bottom gequ 4 right gequ 6 v gequ 0 ;offsets in pen position fields h gequ 2 ***************************************************************** * MainLoop start * * Main program loop: * ***************************************************************** using GlobalData phk ;equate program bank plb ; with data bank jsr StartUp ;startup tool sets bcs Quit ;boot disk not online jsr InitDesktop ;initialize desktop jsr InitApplic ;initialize application jsr EventLoop ;scan for events jsr ShutApplic ;free program memory jsr ShutDown ;shutdown tool sets Quit _QuitGS QuitParm ;quit to calling application ;................................................................ ; ; MainLoop data: ; QuitParm anop ;Quit parmlist (GS/OS class 1) dc i2'0' ;pCount = 0 (input) end ***************************************************************** * InitDesktop start * * Initialize desktop: * ***************************************************************** PushLong #0 ;refresh entire desktop _RefreshDesktop ldx #MTIndex ;get index to last entry in menu table MenuLoop phx ;save index to menu table PushLong #0 ;space for result lda MenuTable+2,x ;ptr hi to menu template pha ; (menu lines and item lines) lda MenuTable,x ;ptr lo to menu template pha ; (menu lines and item lines) _NewMenu ;create new menu in system menu bar PushWord #0 ;insert menu in front of other menus _InsertMenu ;insert specified menu in menu list plx ;retrieve index to menu table dex ;get next entry in menu table dex dex dex bpl MenuLoop ;loop back for another menu PushWord #1 ;ID of NDA menu _FixAppleMenu ;setup NDA menu pha ;space for result _FixMenuBar ;set standard size of menu bar pla ;discard menu height _DrawMenuBar ;display system menu bar rts ;................................................................ ; ; InitDesktop data: ; MenuTable anop ;table of ptrs to menu templates below dc i4'AppleMenu' dc i4'FileMenu' dc i4'EditMenu' MTIndex equ *-MenuTable-4 ;index to last entry in table AppleMenu dc c'>>@\N1X',h'00' dc c'--About File Reader...\N256',h'00' dc c'---\N300D',h'00' dc c'.' FileMenu dc c'>> File \N2',h'00' dc c'--Open File...\N257*Oo',h'00' dc c'--Close\N255*WwD',h'00' dc c'---\N300D',h'00' dc c'--Choose Printer...\N258D',h'00' dc c'--Page Setup...\N259D',h'00' dc c'--Print File...\N260*PpD',h'00' dc c'---\N300D',h'00' dc c'--Quit\N261*Qq',h'00' dc c'.' EditMenu dc c'>> Edit \N3',h'00' dc c'--Undo\N250*ZzD',h'00' dc c'--Cut\N251*XxD',h'00' dc c'--Copy\N252*CcD',h'00' dc c'--Paste\N253*VvD',h'00' dc c'--Clear\N254D',h'00' dc c'.' end ***************************************************************** * InitApplic start * * Initialize application specific data: * ***************************************************************** using GlobalData stz QuitFlag ;clear quit flag stz PrtRecHndl ;zero print record handle stz PrtRecHndl+2 tdc ;save application's direct page sta MyDP ; for window update handler rts end ***************************************************************** * EventLoop start * * Handle events: * ***************************************************************** using GlobalData ; Scan for events with TaskMaster: pha ;space for result PushWord #$FFFF ;handle all events PushLong #TaskRecord ;ptr to extended task record _TaskMaster ;get the event pla ;get result ; Handle event: asl a ;create index into 2-byte tax ; entries of task table jsr (TaskTable,x) ;call event handler ; Check for quit signal: lda QuitFlag bpl EventLoop ;Quit not chosen so keep scanning rts ;................................................................ ; ; EventLoop data: ; TaskTable anop ;GetNextEvent event handlers: dc i2'DoNull' ; 0 = nullEvt dc i2'DoRTS' ; 1 = mouseDownEvt dc i2'DoRTS' ; 2 = mouseUpEvt dc i2'DoRTS' ; 3 = keyDownEvt dc i2'DoRTS' ; 4 = undefined dc i2'DoRTS' ; 5 = autoKeyEvt dc i2'DoRTS' ; 6 = updateEvt dc i2'DoRTS' ; 7 = undefined dc i2'DoRTS' ; 8 = activateEvt dc i2'DoRTS' ; 9 = switchEvt dc i2'DoRTS' ;10 = deskAccEvt dc i2'DoRTS' ;11 = driverEvt dc i2'DoRTS' ;12 = app1Evt dc i2'DoRTS' ;13 = app2Evt dc i2'DoRTS' ;14 = app3Evt dc i2'DoRTS' ;15 = app4Evt anop ;TaskMaster event handlers: dc i2'DoRTS' ;16 = wInDesktop dc i2'DoMenu' ;17 = wInMenuBar dc i2'DoRTS' ;18 = wClickCalled dc i2'DoRTS' ;19 = wInContent dc i2'DoRTS' ;20 = wInDrag dc i2'DoRTS' ;21 = wInGrow dc i2'DoClose' ;22 = wInGoAway dc i2'DoRTS' ;23 = wInZoom dc i2'DoRTS' ;24 = wInInfo dc i2'DoMenu' ;25 = wInSpecial dc i2'DoRTS' ;26 = wInDeskItem dc i2'DoRTS' ;27 = wInFrame dc i2'DoRTS' ;28 = wInactMenu dc i2'DoRTS' ;29 = wClosedNDA dc i2'DoRTS' ;30 = wCalledSysEdit dc i2'DoRTS' ;31 = wTrackZoom dc i2'DoRTS' ;32 = wHitFrame end ***************************************************************** * DoMenu start * * Handle menu events (menu items must be numbered sequentially): * ***************************************************************** using GlobalData sec lda TaskData ;get menu item ID sbc #250 ;convert N250 into 1st (0th) item asl a ;create index into 2-byte entries tax ; of menu item table jsr (ItemTable,x) ;call menu item handler PushWord #0 ;TRUE=highlight, FALSE=unhighlight PushWord TaskData+2 ;menu ID _HiliteMenu ;unhighlight menu rts ;................................................................ ; ; DoMenu data: ; ItemTable anop ;menu item handlers dc i2'DoRTS' ;250 = Undo dc i2'DoRTS' ;251 = Cut dc i2'DoRTS' ;252 = Copy dc i2'DoRTS' ;253 = Paste dc i2'DoRTS' ;254 = Clear dc i2'DoClose' ;255 = Close dc i2'DoAbout' ;256 = About... dc i2'DoOpen' ;257 = Open File dc i2'DoChooser' ;258 = Choose Printer... dc i2'DoSetup' ;259 = Page Setup... dc i2'DoPrint' ;260 = Print File... dc i2'DoQuit' ;261 = Quit end ***************************************************************** * ShutApplic start * * Deallocate memory before shutting down tool sets: * ***************************************************************** using GlobalData jsr DoClose ;close front window, if open lda FrontWinPtr ;check for open window ora FrontWinPtr+2 bne ShutApplic ;another window open PushLong PrtRecHndl ;handle to print record _DisposeHandle ;deallocate print record space rts end ***************************************************************** * DoRTS start * * Ignore an event: * ***************************************************************** rts end ***************************************************************** * DoQuit start * * Turn on quit flag to terminate this application: * ***************************************************************** using GlobalData lda #$8000 sta QuitFlag ;set quit flag rts end ***************************************************************** * DoNull start * * Enable or disable menu items during null events: * ***************************************************************** using GlobalData PushLong #0 ;space for result _FrontWindow ;get ptr to front window PullLong FrontWinPtr ;save ptr anop ;stack menu items: PushWord #250 ;Undo PushWord #251 ;Cut PushWord #252 ;Copy PushWord #253 ;Paste PushWord #254 ;Clear PushWord #255 ;Close PushWord #258 ;Choose Printer... PushWord #259 ;Page Setup... PushWord #260 ;Print File... lda FrontWinPtr ;check for open window ora FrontWinPtr+2 beq NoWind ;no window open pha ;space for result PushLong FrontWinPtr ;ptr to front window _GetWKind ;get window type pla ;PL = application, MI = system bpl ApplicWind anop ;NDA window in front _DisableMItem ;dim print items _DisableMItem _DisableMItem _EnableMItem ;hilite special items _EnableMItem _EnableMItem _EnableMItem _EnableMItem _EnableMItem rts ApplicWind anop ;application window in front _EnableMItem ;hilite print items _EnableMItem _EnableMItem _EnableMItem ;hilite Close item bra DimEdit ;dim Edit menu items NoWind anop ;no window open _DisableMItem ;dim print items and special items _DisableMItem _DisableMItem _DisableMItem DimEdit _DisableMItem _DisableMItem _DisableMItem _DisableMItem _DisableMItem rts end ***************************************************************** * DoClose start * * Close front window: * ***************************************************************** using GlobalData PushLong #0 ;space for result _FrontWindow ;get ptr to front window PullLong FrontWinPtr ;save ptr lda FrontWinPtr ;check for open window ora FrontWinPtr+2 beq Done ;no window open PushLong FrontWinPtr ;ptr to front window _CloseNDAbyWinPtr ;close NDA window bcc Done ;NDA window closed PushLong DataBufHndl ;handle to file data buffer _DisposeHandle ;deallocate handle and free memory jsr HandlErr PushWord #257 ;enable Open File item _EnableMItem PushLong FrontWinPtr ;ptr to front window _CloseWindow ;close application window Done rts end ***************************************************************** * DoAbout start * * Handle About item in Apple menu (display title and credits): * ***************************************************************** pha ;space for result PushWord #0 ;C-string PushLong #0 ;no substitution array PushLong #AlertStr ;ptr to alert string _AlertWindow ;display alert window pla ;discard button ID (always OK button) rts ;................................................................ ; ; DoAbout data: AlertStr anop ;alert string dc c'0',i'50,160,125,480' ;coordinates dc c'0/' ;no icon, separator dc h'01',c'J',i'1' ;center text dc h'01',c'S',i'1' ;bold text dc h'0D',c'Ascii File Reader',2h'0D' ;title dc h'01',c'S',i'0' ;standard text dc c'by Sandy Mossberg',h'0D' ;credits dc c'(c)1989 by MindCraft Publ. Corp.' dc c'/^#0' ;separator, OK default dc h'00' ;zero terminator end ***************************************************************** * GlobalData data * * Global program data: * ***************************************************************** MasterID ds 2 ;master memory ID of application MyDP ds 2 ;direct page of application QuitFlag ds 2 ;quit flag FrontWinPtr ds 4 ;ptr to front window PenLoc ds 4 ;coordinates of pen position LeftEdge ds 2 ;left margin of page TaskRecord anop ;extended event record for TaskMaster What ds 2 ;event code Message ds 4 ;event message When ds 4 ;ticks since startup Where ds 4 ;global position of mouse Modifiers ds 2 ;state of modifier keys TaskData ds 4 ;extended event data TaskMask dc i4'$FFFF' ;bit flag (ignore no functions) EOFParm anop ;GetEOF parmlist (GS/OS class 1) dc i2'2' ;pCount = 2 (input) EOFRefNum ds 2 ;reference number (input) EOF ds 4 ;size of file in bytes (result) end copy basics.asm copy fr.options.asm